<template>
  <div class="popup" v-if="visable">
    <div class="dialog">
      <div class="title" v-if="title">{{title}}</div>
      <div class="content">
        <slot></slot>
      </div>
      <div class="btn">
        <button v-if="cancelBtn" @click="cancel">{{cancelBtn?cancelBtn:'取消'}}</button>
        <button v-if="confirmBtn" @click="confirm">{{confirmBtn?confirmBtn:'确认'}}</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CDialog",
  props: {
    title: {
      type: [String],
      default: ''
    },
    cancelBtn: {
      type: [String],
      default: ''
    },
    confirmBtn: {
      type: [String],
      default: ''
    }
  },
  data(){
    return {
      visable: false
    }
  },
  methods: {
    show(){
      this.visable = true
    },
    hide(){
      this.visable = false
    },
    cancel(){
      this.hide()
    },
    confirm(){
      this.$emit('confirm')
      this.hide()
    }
  }
}
</script>

<style lang='stylus'>
  @import '../../assets/css/dialog.styl';
</style>